﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interactivity;

namespace MuddyBoots.GreenlightQC.Mobile.UI.View.Triggers
{
    public class PasswordtBoxEnterKeyTrigger : TriggerBase<UIElement>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            this.AssociatedObject.KeyUp += this.AssociatedObject_KeyUp;
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            this.AssociatedObject.KeyUp -= AssociatedObject_KeyUp;
        }

        void AssociatedObject_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                PasswordBox passwordBox = AssociatedObject as PasswordBox;
                object parameter = passwordBox == null ? null : passwordBox;
                if (parameter != null)
                {
                    this.InvokeActions(parameter);
                }
            }
        }
    }
}
